package com.zx.map.dao.impl;

import com.zx.map.dao.ConsumeLogDao;
import com.zx.map.dao.mapper.ConsumeLogMapper;
import com.zx.map.dao.model.ConsumeLog;
import com.zx.map.dao.model.ConsumeLogExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by IntelliJ IDEA. User: Administrator Date: 14-3-1 Time: 上午10:54 To
 * change this template use File | Settings | File Templates.
 */
@Component("consumeLogDao")
public class ConsumeLogImpl implements ConsumeLogDao {

	@Autowired
	private ConsumeLogMapper mapper;

	/**
	 * 新增
	 */
	public String add(ConsumeLog consumeLog) throws DataAccessException {
		int column = mapper.insert(consumeLog);
		if (column != 1) {
			throw new RuntimeException("");
		}
		return consumeLog.getConsumeId();
	}

	/**
	 * 修改
	 * 
	 * @param consumeLog
	 * @return
	 * @throws org.springframework.dao.DataAccessException
	 * 
	 */
	public String update(ConsumeLog consumeLog) throws DataAccessException {
		int column = mapper.updateByPrimaryKeySelective(consumeLog);
		if (column != 1) {
			throw new RuntimeException("");
		}
		return consumeLog.getConsumeId();
	}

	/**
	 * 删除
	 */
	public void delete(ConsumeLog consumeLog) throws DataAccessException {
		int column = mapper.deleteByPrimaryKey(consumeLog.getConsumeId());
		if (column != 1) {
			throw new RuntimeException("");
		}
	}

	/**
     *
     */
	public List<ConsumeLog> getListByExample(ConsumeLogExample example)
			throws DataAccessException {
		return mapper.selectByExample(example);
	}

	/**
    *
    */
	public int countListByExample(ConsumeLogExample example)
			throws DataAccessException {
		return mapper.countByExample(example);
	}

	/**
	 * 根据筛选的记录 更新某个字段
	 */
	public void updateByExample(ConsumeLog consumeLog, ConsumeLogExample example)
			throws DataAccessException {
		mapper.updateByExampleSelective(consumeLog, example);
	}

	/**
	 * 分页查找
	 */
	public List<ConsumeLog> getPageByExample(int pageSize, int pageBegin,
			ConsumeLogExample example) throws DataAccessException {
		return mapper.getPageByModel(pageSize, pageBegin, example);
	}
}
